home *** CD-ROM | disk | FTP | other *** search
- ** Copyright ©1989, 1990 by Imagine That, Inc.
- ** All Rights Reserved.
- ** Extend EcoSphere Lib, Fauna universalis; Bob Diamond
- ** modified 7/21/90 BD
- ** creature[n][0] is the current starving age of the creature
- ** creature[n][1] is the current breeding age of the creature
- ** if these ages become greater or equal to zero, the creature
- ** starves or breeds as required
-
- Integer Creature[][2], initAlive, MaxCreatures, starveMn;
- integer breedR, minSv, starveR, alive, breedMn, TwoMaxCreatures;
- integer preyConnected;
-
- Constant NONE is -1000000;
-
- on simulate
- {
- integer foods, new, i, j, starveAge, eaten, dummyInt;
- integer diedNow, breedAge, foodEaten, feedAll, NewStarveAge;
-
- ** how many food units came in the F connector
- foods = EatFoodOutIn/foodMult+0.5;
-
- ** feed our creatures with food units
- feedAll = FALSE;
- foodEaten = 0;
- if (foods < TwoMaxCreatures)
- {
- for (i=0; i<foods; i++)
- {
- j = random(MaxCreatures);
- starveAge = Creature[j][0];
- if (starveAge != NONE)
- {
- Creature[j][0] -= (starveMn+random(starveR)); ** feed creature, age 0
- foodEaten = foodEaten+1;
- }
- }
- }
- else
- feedAll = TRUE; ** more food than 2 times the population
-
- ** now, see if any eaten by a predator to the right
- if (currentStep == 0 OR NOT preyConnected) ** none eaten initially
- eaten = 0;
- else
- eaten = alive-minSv-SupplyFoodOutIn; ** live ones eaten
-
- i = 0;
- while (eaten > 0 AND i<MaxCreatures)
- {
- if (Creature[i][0] != NONE)
- {
- Creature[i][0] = NONE; ** remove eaten creature
- eaten--; ** decrement eaten
- alive--; ** decrement alive
- }
- i++; ** increment index
- }
-
- diedNow = 0;
- new = 0;
- NewStarveAge = 0;
-
- ** count, test the population for breeding, starving age
- for (i=0; i<MaxCreatures; i++)
- {
- starveAge = Creature[i][0]; ** current age for this one
-
- if (starveAge != NONE) ** a living one
- {
- if (feedAll) ** more than enough food
- {
- starveAge = -(starveMn+random(starveR));
- Creature[i][0] = starveAge;
- foodEaten = foodEaten+1;
- }
- else
- {
- starveAge = starveAge+1;
- Creature[i][0] = starveAge; ** age Creature
- }
-
- if (starveAge >= 0) ** greater than starving age
- {
- Creature[i][0] = NONE; ** creature is removed
- diedNow++; ** increment diedNow
- alive--;
- }
- else
- {
- breedAge = Creature[i][1];
- breedAge = breedAge+1;
- Creature[i][1] = breedAge; ** age Creature
-
- if (breedAge >= 0)
- {
- Creature[i][1] = -(breedMn+random(breedR)); ** age Creature
- new = new+MeanOffspring;
- }
- }
- }
- }
-
- if (alive < minSv)
- new = new+minSv-alive; ** make sure we have minimum
-
- ** now, place new Creatures
- i = 0;
- while (new > 0 && i<MaxCreatures)
- {
- if (Creature[i][0] == NONE)
- {
- Creature[i][0] = -(starveMn+random(starveR)); ** age Creature
- Creature[i][1] = -(breedMn+random(breedR)); ** age Creature
- new--;
- alive++; ** increment alive
- }
- i++; ** increment index
- }
-
- AliveOut = alive; ** for plotting the population
-
- SupplyFoodOutIn = alive-minSv; ** don't use min survivors
-
- deadOutIn += diedNow*CarrionEquiv; ** add dead to connector
-
- EatFoodOutIn -= int(foodEaten*foodMult+0.5); ** round it
- }
-
-
- on initsim
- {
- integer i;
-
- initAlive = initCreatures;
- alive = initAlive;
- MaxCreatures = maximumCreatures;
- TwoMaxCreatures = MaxCreatures*2;
-
- breedMn = BreedMean*0.5+1;
- breedR = BreedMean+1;
-
- starveMn = StarveMean*0.5+1; ** compensation
- starveR = StarveMean;
-
- minSv = minSurvive;
- makeArray(Creature, MaxCreatures);
- for (i=0; i<initAlive; i++)
- {
- Creature[i][0] = -(starveMn+random(starveR)); ** new Creature, age 1
- Creature[i][1] = -(breedMn+random(breedR)); ** new Creature
- }
-
- for (i=initAlive; i<MaxCreatures; i++)
- Creature[i][0] = NONE; ** no Creature
- }
-
-
- on checkData ** is dialog data valid for simulation?
- {
- if (novalue(initCreatures+maximumCreatures+BreedMean+StarveMean
- +MeanOffspring+CarrionEquiv+foodMult+minSurvive))
- abort;
-
- if (initCreatures > maximumCreatures)
- {
- userError("initCreatures="+initCreatures+" maxCreatures="+maximumCreatures);
- userError("Initial number of creatures must be less than or equal to the maximum number.");
- abort;
- }
-
- preyConnected = SupplyFoodOutIn; ** TRUE if connected
- }
-
- on CreateBlock
- {
-
- ** Default values
-
- initCreatures = 10;
- BreedMean = 10;
- MeanOffspring = 10;
-
- maximumCreatures = 300;
- minSurvive = 2;
- StarveMean = 3;
-
- FoodMult = 1.0;
- CarrionEquiv = 10;
- }
-
-